<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选项卡</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        /* [class^='current'] {
            border-bottom: 1px solid !important;
        } */

        .current0 {
            background-color: pink;
            border-bottom: 1px solid pink !important;
            color: #fff;
        }

        .current1 {
            background-color: orange;
            border-bottom: 1px solid orange !important;
            color: #fff;
        }

        .current2 {
            background-color: green;
            border-bottom: 1px solid green !important;
            color: #fff;
        }

        .current3 {
            background-color: yellowgreen;
            border-bottom: 1px solid yellowgreen !important;
            color: #fff;
        }

        .clearfix::after {
            content: '';
            display: block;
            clear: both;
            height: 0;
            visibility: hidden;
        }

        .tab {
            margin: 200px 0 0 100px;
        }

        .tab_list ul li {
            float: left;
            height: 30px;
            padding: 0 40px;
            border: 1px solid #000;
            border-right: 0;
            list-style: none;
            text-align: center;
            line-height: 30px;
            cursor: pointer;
        }

        .tab_list ul li:last-child {
            border-right: 1px solid #000;
        }

        .tab_con {
            position: relative;
            width: 451px;
            height: 200px;
            border: 1px solid #000;
            border-top: 0;
            font-size: 20px;
            line-height: 200px;
            text-align: center;
        }

        .tab_con .item {
            position: absolute;
            display: none;
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
    <div class="tab">
        <div class="tab_list">
            <ul class="clearfix">
                <li class="current0">手机</li>
                <li>电脑</li>
                <li>服装</li>
                <li>家电</li>
            </ul>
        </div>
        <div class="tab_con">
            <div class="item" style="display: block; background-color: pink;">
                手机模块
            </div>
            <div class="item" style="background-color: orange;">
                电脑模块
            </div>
            <div class="item" style="background-color: green;">
                服装模块
            </div>
            <div class="item" style="background-color: yellowgreen;">
                家电模块
            </div>
        </div>
    </div>

    <script>
        var tab_list = document.querySelector('.tab_list');
        var lis = tab_list.querySelectorAll('li');
        var items = document.querySelectorAll('.item');

        for (let i in lis) {
            // lis[i].setAttribute('index', i);
            lis[i].onclick = function () {
                for (let j in lis) {
                    if (j == i) {
                        this.className = "current" + i;
                        items[i].style.display = 'block';

                        // lis[j].className = 'current';
                        continue;
                    }
                    lis[j].className = '';
                    items[j].style.display = 'none';
                }
                // var index = this.getAttribute('index');
                // console.log(index);

                // for (let j in items) {
                //     if (j == i) {
                //         items[i].style.display = 'block';
                //         continue;
                //     }
                //     items[j].style.display = 'none';
                // }
            }
        }
    </script>
</body>

</html>